<template>
	<view>
		<!-- 报警管理详情 -->
		<view class="page">
			<view class="example-body">
				<uni-nav-bar background-color="#003466" color="#ffffff" :status-bar="true" @click-left="back" left-icon="arrowleft" style="position: relative;">
					<view class="flex-item">故障详情</view>
				</uni-nav-bar>
			</view>
			<view class="alarm-container">
				<view class="alarm-option">
					<view class="alarm-optionleft">设备名称</view>
					<view class="alarm-optionright">{{ objData.equipmentRowGuid }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">故障来源</view>
					<view class="alarm-optionright">{{ objData.source }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">故障状态</view>
					<view class="alarm-optionright">{{ objData.status }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">故障优先级</view>
					<view class="alarm-optionright">{{ objData.priorityLevel }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">所属专业队</view>
					<view class="alarm-optionright">{{ objData.teamRowGuid }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">开始时间</view>
					<view class="alarm-optionright">{{ objData.startTime }}</view>
				</view>
				<view class="alarm-option">
					<view class="alarm-optionleft">结束时间</view>
					<view class="alarm-optionright">{{ objData.endTime }}</view>
				</view>
				<view class="alarm-option newoption">
					<view class="alarm-optioninput">故障描述</view>
					<textarea :value="objData.description" placeholder="请输入" class="alarm-input"></textarea>
				</view>
			</view>
			<view class="alarm-write" v-if="receiveState" @click="receive">确认接收</view>
			<view class="alarm-write" v-if="writeState" @click="writeFault" v-show="false">填写故障处理记录</view>
		</view>
	</view>
</template>

<script>
import uniDrawer from '@/components/uni-drawer/uni-drawer.vue';
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import uniIcon from '@/components/uni-icon/uni-icon.vue';
import tools from '@/common/tools-new.js';
export default {
	data() {
		return {
			objData: [], //详情获取
			objInf: [],
			dic_data: [
				{
					name: '故障来源',
					data: []
				},
				{
					name: '所属系统',
					data: []
				},
				{
					name: '优先级别',
					data: []
				}
			],
			receiveState: false,
			writeState: true,
			passParam: {
				id: '',
				eqId: '',
				result: '',
				createTime: '',
				status: '' //
			} //传递的多个参数
		};
	},
	components: {
		uniNavBar,
		uniIcon
	},
	methods: {
		//数据来源
		getOptionList(id) {
			let param = { id: id };
			this.$api.MalfManage.MalfOption(param).then(res => {
				console.log(res[1].data.result);

				this.objData = res[1].data.result;
				this.passParam.id = this.objData.id;
				this.passParam.eqId = this.objData.equipmentRowGuid;
				this.passParam.result = this.objData.result;

				this.getequipName(this.objData.equipmentRowGuid);
				// console.log(this.objData)
				this.getTeamName(this.objData.teamRowGuid);
				//取所属系统名称
				if (this.objData != null) {
					this.objData.source = this.$helper.getTextByValue('故障来源', this.objData.source);
					this.objData.status = this.$helper.getTextByValue('所属系统', this.objData.status);
					this.objData.priorityLevel = this.$helper.getTextByValue('优先级别', this.objData.priorityLevel);
					this.objData.startTime = this.$helper.dateFormat(this.objData.startTime, false);
					this.objData.endTime = this.$helper.dateFormat(this.objData.endTime, false);
				}
			});
		},

		getTeamName(id) {
			console.log('zhuayid' + id);
			this.$api.MalfManage.TeamNama({ id: id })
				.then(res => {
					console.log(res[1].data.result);
					this.objData.teamRowGuid = res[1].data.result.teamName==undefined ?'--':res[1].data.result.teamName ;
					// this.objData.teamRowGuid = jiekou.teamName;
				})
				.catch(res => {
					//接口请求失败
					uni.showToast({
						title: '接口数据请求失败',
						duration: 2000
					});
				});
		},

		//初始化设备名称数据
		getequipName(id) {
			this.$api.MalfManage.EquiName({ id: id })
				.then(res => {
					console.log(res);
					this.objData.equipmentRowGuid = res[1].data.result.equipmentName;
					// this.objData = res[1].data.result;
				})
				.catch(res => {
					//接口请求失败
					uni.showToast({
						title: '接口数据请求失败',
						duration: 2000
					});
				});
		},

		back() {
			uni.navigateBack({
				delta: 1
			});
		},

		writeFault() {
			uni.navigateTo({
				url: 'malfunction-manage-notes?passParam=' + JSON.stringify(this.passParam)
			});
		},

		//确认接收
		receive() {
			let params = {
				id: this.passParam.id,
				state: '002'
			};
			this.$api.MalfManage.ReciveTask(params)
				.then(res => {
					if (res[1].data.success) {
						uni.showToast({
							title: '接收成功',
							duration: 2000
						});
						wx.redirectTo({
							url: 'malfunction-manage-list'
						});
					}
				})
				.catch(res => {
					// 失败进行的操作/给出提示
					uni.showToast({
						title: '接收失败',
						duration: 2000
					});
				});
		}
	},

	onLoad: async function(option) {
		this.getOptionList(option.id);
		this.passParam.status = option.status;
		if (option.status == '001') {
			this.receiveState = true;
			this.writeState = false;
		} else {
			this.receiveState = false;
			this.writeState = true;
		}
	}
};
</script>

<style>
page {
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	background-color: #F2F2F2;
}

.flex-item {
	font-size: 20px;
	text-align: center;
}

.uni-icon {
	padding-left: 42%;
}

.uni-navbar__header-btns:last-child {
	width: 120px;
}

.uni-navbar__header-btns {
	padding: 0;
}
/* 头部样式 */
.alarm-container {
	width: 94%;
	margin: 0 auto;
	margin-top: 10px;
	background-color: #ffffff;
	border-radius: 3px;
	overflow: hidden;
}

.alarm-option {
	width: 96%;
	border-bottom: 1px solid #eeeeee;
	overflow: hidden;
	font-size: 16px;
	margin: 0 auto;
	padding: 14px 0px;
}

.alarm-optionleft {
	float: left;
	color: #333333;
}

.alarm-optionright {
	float: right;
	color: #666666;
}

.alarm-input {
	width: 96.9%;
	font-size: 14px;
	float: inherit;
	border: 1px solid #e5e5e5;
	margin-top: 10px;
	padding: 10px;
}

.alarm-optioninput {
	color: #333333;
}

textarea {
	height: 100px;
	color: #666666;
}

.newoption {
	border: none;
	overflow: hidden;
}

input {
	outline: none;
}

.alarm-write {
	width: 94%;
	height: 52px;
	line-height: 52px;
	margin: 0 auto;
	border-radius: 3px;
	font-size: 16px;
	color: #ffffff;
	text-align: center;
	background-color: #169bd5;
	margin-top: 15px;
}
</style>
